package com.qidian.mes.easyexcel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @Author 任超
 * Time 2024/10/18 15:54
 */
public class LedgerStatusConverter implements Converter<Integer> {
    /**
     * 将Java Data 转换为 Excel Data   将整型数字转换为字符串
     * @param value               Java Data.NotNull.
     * @param contentProperty     Content property.Nullable.
     * @param globalConfiguration Global configuration.NotNull.
     * @return
     * @throws Exception
     */
    @Override
    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return new WriteCellData<>(value == 1 ? "启用" : value == 2 ? "禁用" : "删除" );
    }
    /**
     * 将字符串转换为整型
     * @param context read converter context
     * @return
     * @throws Exception
     */
    @Override
    public Integer convertToJavaData(ReadConverterContext<?> context) throws Exception {
        String gender = context.getReadCellData().getStringValue();
        return gender.equals("正常") ? 1 : gender.equals("禁用") ? 2 : 3;
    }
}
